package com.aaa.controller.scl;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.mht.QuestionMht;
import com.aaa.entity.scl.QuestionScl;
import com.aaa.service.scl.QuestionSclService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QuestionScl)表控制层
 *
 * @author makejava
 * @since 2022-09-01 13:23:28
 */
@RestController
@RequestMapping("questionScl")
public class QuestionSclController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private QuestionSclService questionSclService;

    @RequestMapping(value = "queryAllScl.do")
    public Result queryAllScl(PageSortEntity pageSortEntity, QuestionScl questionScl) {
        List<QuestionScl> questionSclList = questionSclService.queryAllScl(pageSortEntity, questionScl);
        Page page = (Page) questionSclList;
        return success(page.getResult(), page.getTotal());
    }

    @RequestMapping(value = "saveQuestionScl.do")
    public Result saveQuestionScl(QuestionScl questionScl) {
        Integer save = questionSclService.save(questionScl);
        if (save > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "delQuestionSclById.do")
    public Result delQuestionSclById(Integer id) {
        Integer save = questionSclService.deleteById(id);
        if (save > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "delQuestionSclBatch.do")
    public Result delQuestionSclBatch(int[] id) {
        Integer integer = questionSclService.deleteBatch(id);
        if (integer > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @RequestMapping(value = "updateQuestionScl.do")
    public Result updateQuestionScl(QuestionScl questionScl) {
        Integer update = questionSclService.update(questionScl);
        if (update > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @GetMapping(value = "repetitionName.do")
    public Result repetitionName(QuestionScl questionScl) {
        int i = questionSclService.repetitionName(questionScl);
        if (i > 0) {
            return fail("题目已存在");
        } else {
            return success("题目可使用");
        }
    }
}

